package top.hidoctor.auscultation.feature.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;


import java.util.ArrayList;
import java.util.List;

import top.hidoctor.auscultation.R;
import top.hidoctor.auscultation.adapter.PicAdapter;
import top.hidoctor.auscultation.base.BaseActivity;
import top.hidoctor.auscultation.bean.ModifyHeadBean;

public class FeedBackActivity extends BaseActivity {

    private RecyclerView recyclerview;
    List<ModifyHeadBean> piclist = new ArrayList<>();
    private PicAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_feedback);
        initView();
        initEvent();
    }

    private void initEvent() {
        initRecyler();

    }

    private void initRecyler() {
        GridLayoutManager manager = new GridLayoutManager(mContext, 4);
        recyclerview.setLayoutManager(manager);
        recyclerview.setAdapter(adapter = new PicAdapter(this, piclist));
        adapter.setOnPicItemClicks(new PicAdapter.onPicItemClick() {
            @Override
            public void onClick(int position) {
                if (position >= piclist.size()) {
                    imagePic(8 - piclist.size());
                } else {
                    Intent intent = new Intent(mContext, ShowImgActivity.class);
                    ArrayList<String> listString = new ArrayList<>();
                    for (int i = 0; i < piclist.size(); i++) {
                        listString.add(i, piclist.get(i).getFileUrl());
                    }
                    intent.putStringArrayListExtra("imgs", listString);
                    intent.putExtra("index", position);
                    startActivity(intent);
                }
            }

            @Override
            public void onDelete() {

            }
        });
    }

    private void initView() {
        final Toolbar toolbar = findViewById(R.id.toolbar);
        TextView tvTitle = findViewById(R.id.tv_title);
        toolbar.setNavigationIcon(R.mipmap.ic_back_left);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
                hideSoft(toolbar);
            }
        });
        tvTitle.setText("问题反馈");
        recyclerview = findViewById(R.id.recyclerview);

    }

    private void imagePic(int limit) {

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

    }


}
